<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>充值中心</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/wx_main.css">
    <style>
        .bg {

        }
        a:link {
            text-decoration: none;
        }
        a:visited {
            text-decoration: none;
        }
        a:hover {
            text-decoration: none;
        }
        a:active {
            text-decoration: none;
        }

        .list1 {
       
            height: 160px;
            width: 95%;
            border-radius: 10px;
            margin: 0 auto;
            background: #14b941;
            background: -webkit-linear-gradient(to right, #33d26f, #11998e);
            background: linear-gradient(to right, #33d26f, #11998e);


        }
        .list1 h2{
            padding-top:50px;
            padding-left:20px;
            font-size: 26px;
            font-family: 'Microsoft YaHei', arial, sans-serif, 'Droid Sans Fallback';
            color: #fff;
        }
        .list1 h1{
            margin-top: -75px;
            float: right;
            font-size: 16px;
            font-family: 'Microsoft YaHei', arial, sans-serif, 'Droid Sans Fallback';
            color: #f9f9f9;
            padding: 2px 14px;
            border: 1px solid #fff;
            border-radius: 20px;
            margin-right: 20px;
        }
        .list1 h3{

            padding-left:20px;
            font-size: 16px;
            font-family: 'Microsoft YaHei', arial, sans-serif, 'Droid Sans Fallback';
            color: #fff;

        }
        #tab{
            margin-top: 1rem;
        }
    </style>
    <script type="text/javascript" src="__PUBLIC__/Js/jquery.min.js"></script>

    <script>
        function getorder() {
            var id = {$id};
            $.ajax({
                type: "POST",
                url: "__CONTROLLER__/getorder2",

                cache: false,

                data: {
                    id: id
                },

                success: function (data) {
                    $('#orderid').val(data);

                }
            });

        }
        function checkForm() {
            var id = $('input:radio[name=price]:checked').val();
            var price = $("#price").val();
            if (id > 0 || price > 0) {
                if (price > 0) {
                    var re = /^[1-9]+[0-9]*]*$/;
                    if (!re.test(price) || price < 100)
                        $("#info").html("充值金额不能少于100！");
                    else
                        $("#rechargeForm").submit();
                }
                else {
                    zf();
                }
            }
            else {
                $("#info").html('请选择充值金额或选择其他输入金额！');
            }
        }

        function zf(prices,cid) {

            var price = prices;
            var orderid = $('#orderid').val();
            var openid = $('#openid').val();
            if (price < 0.01) {
                alert('金额不能小于0.01元');
                $('#price').focus();
            } else {

                $.ajax({
                    type: "POST",
                    url: "__CONTROLLER__/pay2/id/{$id}",

                    cache: false,
                    dataType: "json",
                    data: {
                        orderid: orderid,
                        price: price,
                        openid: openid,
                        fs:'cz',
                        c_id:cid,

                    },

                    success: function (data) {
                        onBridgeReady(data);

                    }
                });

            }
        }

        function onBridgeReady(data) {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                data,
                function (res) {
                    WeixinJSBridge.log(res.err_msg);
                    if (res.err_msg === 'get_brand_wcpay_request:ok') {

                        paysuccess();

                    } else {
                        getorder();


                    }

                });
        }

        function paysuccess() {
            var ordid = $('#orderid').val();
            $.ajax({
                type: "POST",
                url: "__CONTROLLER__/payover/id/{$id}/orderid/" + ordid,

                cache: false,
                dataType: "json",
                data: {},

                success: function (data) {
                    if (data === 0) {

                        window.location.replace("__CONTROLLER__/orderinfo/id/{$id}/orderid/" + ordid);
                    } else {

                        alert('支付失败');
                    }
                    ////
                }


            });

        }
    </script>
</head>

<body onload="getorder()">
<!--<div class="top">充值中心</div>-->
<!--<div class="top1"><a href="javascript:void(0);" onclick="window.history.back()"><img-->
        <!--src="__PUBLIC__/images/orderlog_03.png"></a></div>-->
<!--<div class="top2"><a href="/index.php/Recharge/tradeLog">消费记录</a></div>-->

<!-- <form id='tab' method="post">
 <div class="charge_all">
     <div class="charge_left">充值优惠&nbsp;&nbsp;</div>
     <div class="charge_right">
     <table>
             <tbody>
             <volist name='czlist' id='vo'>
                 <tr>
                     <td><input type="radio" name="price" id="price" value="{$vo.price}">{$vo.price}</td>
                 </tr>
             </volist>

             <tr>
                 <td><input type="hidden" name='orderid' id='orderid'/>
                     <input type="hidden" name='openid' value='{$openid}' id='openid'/></td>
             </tr>
             </tbody>
         </table>

        </div>-->
<form id='tab' method="post" class="">
        <div class="bg">
            <volist name='czlist' id='vo'>
             <a href="javascript:void(0)" onclick="zf('{$vo.price}',{$vo.id})"  >
                 <div class="list1">
                    <h2>充值{$vo.price}元</h2>
                    <h3>赠送金额{$vo.free}元</h3>
                     <h1>立即充值</h1>
                </div>
             </a>
            </volist>
        </div>
    </div>
    <input type="hidden" name='orderid' id='orderid'/>
    <input type="hidden" name='openid' value='{$openid}' id='openid'/>

    <!--<div class="charge_all">
        <div class="charge_left">其他金额&nbsp;&nbsp;</div>
        <div class="charge_right"><input type="text" id="price" name="price"><br><span style="color:#f00;" id="info"></span></div>
    </div>
    <div class="charge_all">
        <div class="charge_left">&nbsp;&nbsp;</div>
        <div class="charge_right">
            <button type="button" class="subButton" ">立即充值</button>
        </div>
    </div>-->
</form>


</body>
</html>